package com.cy.src.myaidl.service;

import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;
import android.os.Parcel;
import android.os.RemoteCallbackList;
import android.os.RemoteException;
import android.util.Log;

import com.cy.src.aidl.IMyService;
import com.cy.src.aidl.IMyServiceCallback;


public class MyService extends Service {

    RemoteCallbackList<IMyServiceCallback> mCallbackList = new RemoteCallbackList<>();

    public MyService() {
    }

    public class MyServiceImpl extends IMyService.Stub {

//        @Override
//        public void basicTypes(int anInt, long aLong, boolean aBoolean, float aFloat, double aDouble, String aString) throws RemoteException {
//
//        }

        @Override
        public String helloWorldAidl(String name) throws RemoteException {
            return "helloWorldAidl:name=" + name + "  from app";
        }

        @Override
        public void sendData(String str) throws RemoteException {

        }

        @Override
        public void send(byte[] bundle) throws RemoteException {

        }

        @Override
        public void send2(Bundle bundle) throws RemoteException {

        }

        @Override
        public void registerCallback(IMyServiceCallback callback) throws RemoteException {
            mCallbackList.register(callback);
        }

        @Override
        public void unregisterCallback(IMyServiceCallback callback) throws RemoteException {

        }

        @Override
        public boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
            return super.onTransact(code, data, reply, flags);
        }
    }

    @Override
    public IBinder onBind(Intent intent) {
        // TODO: Return the communication channel to the service.
        return new MyServiceImpl();
    }


    @Override
    public void onCreate() {
        super.onCreate();
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {

        Log.e("MyService", "onStartCommand:" + intent.getStringExtra("key"));
        return super.onStartCommand(intent, flags, startId);
    }
}
